package middol.test

import com.bertram.lock.LockService
import groovy.util.logging.Slf4j

import static java.util.Calendar.DATE

class LockTest1Job {
    LockService lockService
    static triggers = {
//      simple repeatInterval: 5000l // execute job once in 5 seconds
        cron name:'ppmCronTrigger', cronExpression: '0 16 10 * * ?'
    }

    def execute() {
        // execute job
        println("执行111111111")
        log.info("执行111111111")
        def lock
        try {
            lock = lockService.acquireLock('job_bi_updatePPM', [timeout: 1])
            if (lock) {
                def date = new Date()
                def lastDate = date.updated(date: date[DATE] - 1).format("yyyy-MM-dd")
                def sqlCondition = " date_format(load_time, '%Y-%m-%d') = ${lastDate}"
                println sqlCondition
                println("11111111111111等待执行")
                Thread.sleep(30001)
                println("程序执行111111111111111111")
                log.info("程序执行111111111111111111")
            }else {
                println("未获取到锁1111。。。。")
                log.info("未获取到锁111111111。。。。")
            }
        }catch(e){
            e.printStackTrace()
        }finally{
            lockService.releaseLock("job_bi_updatePPM", [lock: lock])
        }
    }
}
